package com.ruoyi.web.controller.system

import com.ruoyi.common.annotation.Log
import com.ruoyi.common.core.controller.BaseController
import com.ruoyi.common.core.domain.AjaxResult
import com.ruoyi.common.core.page.TableDataInfo
import com.ruoyi.common.enums.BusinessType
import com.ruoyi.system.domain.SysNotice
import com.ruoyi.system.service.ISysNoticeService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*

/**
 * 公告 信息操作处理
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/notice")
open class SysNoticeController : BaseController() {

    @Autowired
    private lateinit var noticeService:ISysNoticeService

    /**
     * 获取通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('system:notice:list')")
    @GetMapping("/list")
    open  fun list(notice: SysNotice?): TableDataInfo {
        startPage()
        val list = noticeService.selectNoticeList(notice)
        return getDataTable(list)
    }

    /**
     * 根据通知公告编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:notice:query')")
    @GetMapping(value = ["/{noticeId}"])
    open  fun getInfo(@PathVariable noticeId: Long?): AjaxResult {
        return success(noticeService.selectNoticeById(noticeId))
    }

    /**
     * 新增通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:notice:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    open   fun add(@Validated @RequestBody notice: SysNotice): AjaxResult {
        notice.createBy=username
        return toAjax(noticeService.insertNotice(notice))
    }

    /**
     * 修改通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:notice:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    open  fun edit(@Validated @RequestBody notice: SysNotice): AjaxResult {
        notice.updateBy=username
        return toAjax(noticeService.updateNotice(notice))
    }

    /**
     * 删除通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:notice:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{noticeIds}")
    open  fun remove(@PathVariable noticeIds: Array<Long>): AjaxResult {
        return toAjax(noticeService.deleteNoticeByIds(noticeIds))
    }
}
